package com.example.webgobang.component;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class OnlineUserManager {
    private final Map<Integer, WebSocketSession> gameHall = new ConcurrentHashMap<>(); //大厅中的在线用户
    private final Map<Integer, WebSocketSession> gameRoom = new ConcurrentHashMap<>(); //游戏房间中的在线用户

    public void enterGameHall(int id, WebSocketSession session) {
        gameHall.put(id, session);
    }

    public void exitGameHall(int id) {
        gameHall.remove(id);
    }

    public WebSocketSession getSessionFromGameHall(int id) {
        return gameHall.get(id);
    }

    public void enterGameRoom(int id, WebSocketSession session) {
        gameRoom.put(id, session);
    }

    public void exitGameRoom(int id) {
        gameRoom.remove(id);
    }

    public WebSocketSession getSessionFromGameRoom(int id) {
        return gameRoom.get(id);
    }
}
